﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_BankAccounts : System.Web.UI.Page
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void CreateAccountButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Admin/OpenBankAccount.aspx");
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string accountId = GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text;
        var accounts = from account in db.BankAccounts where account.BankAccountId == Convert.ToInt32(accountId) select account;
        accounts.First().Amount = 0;
        db.SubmitChanges();
        Response.Redirect("~/Admin/BankAccounts.aspx");
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            LinkButton linkButton = (LinkButton)e.Row.FindControl("AddLink");
            string companyId = e.Row.Cells[1].Text.ToString();
            linkButton.CommandArgument = companyId;
        }
    }

    protected void ClickAddMoney(object sender, EventArgs e)
    {
        LinkButton linkButton = (LinkButton)sender;
        Session.Add("bankAccountId", linkButton.CommandArgument);
        Response.Redirect("~/Admin/AddMoney.aspx");
    }
}